package com.auth.control.auth;

import com.auth.domain.service.IUserService;
import com.auth.sdk.LoginInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/authentication")
@Slf4j
@Api(tags = "登录")
public class LoginController {

    @Autowired
    private IUserService userService;

    /**
     * Authentication in string 密码需要RSA加密
     *
     * @param loginId login id
     * @param pwd     pwd
     * @return the string
     */
    @GetMapping(value = "/in", produces = "application/json; charset=UTF-8")
    @ApiOperation("认证")
    public String authenticationIn(@RequestHeader("loginId") String loginId, @RequestHeader("pwd") String pwd) {
        return userService.authenticationIn(loginId, pwd);
    }

    @GetMapping("/out")
    @ApiOperation("退出认证")
    public void authenticationOut(@RequestHeader("id") String id, @RequestHeader("token") String token) {
        userService.authenticationOut(id, token);
        return;
    }

    @GetMapping("/info")
    @ApiOperation("获取认证信息")
    public LoginInfo authenticationInfo(@RequestHeader("token") String token) {
        return userService.authenticationInfo(token);
    }
}

